package com.power.taskcenter.tasks.custom;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import com.power.taskcenter.anno.RegisterTask;
import com.power.taskcenter.service.IDynamicTaskLogsService;
import com.power.taskcenter.service.JobsExecuteService;
import com.power.taskcenter.tasks.DyTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时一个小时一次加工首页
 * <p>
 * Sting Created in 2019-11-13 17:44
 */
@Component
@Slf4j
public class JobWarningDyTask implements DyTask {
    @Autowired
    private IDynamicTaskLogsService dynamicTaskLogsService;

    @Autowired
    private JobsExecuteService jobsExecuteService;

    @RegisterTask( name = "预警加工", remark = "预警加工15分钟加工一次", cron = "0 0/15 * * * ?")
    @Override
    public void run() {
        TimeInterval timer = DateUtil.timer();
        String retStr = "成功";
        dynamicTaskLogsService.saveLogs("jobWarningDyTask","预警加工 P_SCHOOLMONITOR_WARNING2015.WARNING_STATISTICS(NULL) 开始 ");
        try{
            dynamicTaskLogsService.saveLogs("jobWarningDyTask",new Date());
            jobsExecuteService.jobWarning();
        }catch (Exception e){
            retStr = "失败"+e.getLocalizedMessage();
        }
        Long ll = timer.intervalRestart();
        dynamicTaskLogsService.saveLogs("jobWarningDyTask","预警加工 P_SCHOOLMONITOR_WARNING2015.WARNING_STATISTICS(NULL) 结束 "+retStr+" "+ll+" 毫秒 ");
        log.info("jobWarningDyTask 预警加工 P_SCHOOLMONITOR_WARNING2015.WARNING_STATISTICS(NULL) 结束 "+retStr+" "+ll+" 毫秒 ");
    }
}
